import io.lettuce.core.MapScanCursor;
import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;

import java.util.List;

public class RedisTestHash {
    RedisClient redisClient;
    StatefulRedisConnection<String, String> connection;

    public void link(){
        redisClient = RedisClient.create("redis://localhost");
        connection = redisClient.connect();
        System.out.println("初始化");

    }


    public void addHash(){
        connection.sync().hset("set","set1","test1");
        connection.sync().hset("set","set2","test2");
        List<String> set = connection.sync().hkeys("set");
        for(String s:set){
            System.out.println(s);
        }
        set = connection.sync().hvals("set");
        for(String s:set){
            System.out.println(s);
        }
    }


    public void delHash(){
        List<String> set = connection.sync().hkeys("set");
        for(String s:set){
            System.out.println(s);
        }
        connection.sync().hdel("set","set2");
        set = connection.sync().hkeys("set");
        for(String s:set){
            System.out.println(s);
        }
    }


    public void getHash(){
        List<String> set = connection.sync().hvals("set");
        for(String s:set){
            System.out.println(s);
        }

        String hget = connection.sync().hget("set", "set3");
        System.out.println(hget);
    }


    public void finish(){
        connection.close();
        redisClient.shutdown();
        System.out.println("结束");
    }

    public static void main(String[] args) {
        RedisTestHash redisTestHash=new RedisTestHash();
        redisTestHash.link();
    }
}